function flash(message, type = "info") {
    const flashMessage = document.createElement("div");
    flashMessage.className = `alert alert-${type} alert-dismissible fade show`;
    flashMessage.role = "alert";
    flashMessage.innerHTML = `
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        </button>
        ${message}
    `;

    document.body.appendChild(flashMessage);

    flashMessage.style.position = "fixed";
    flashMessage.style.top = "20px";
    flashMessage.style.left = "50%";
    flashMessage.style.transform = "translateX(-50%)";
    flashMessage.style.zIndex = "1050";
    flashMessage.style.width = "auto";
    flashMessage.style.maxWidth = "400px";
    flashMessage.style.boxShadow = "0 2px 10px rgba(0,0,0,0.2)";

     setTimeout(() => {
        flashMessage.classList.remove("show");
        flashMessage.classList.add("fade");
        setTimeout(() => {
            flashMessage.remove();
            location.reload();
        }, 1000);
    }, 1200);
}
